package br.com.loja.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @brief Classe PropertiesApp
 * @author David Luiz
 * @date 18/11/2014
 */
public class PropertiesApp {

    private static final String PROPERTIES_FILE = "/app.properties";
    private static final Properties properties = new Properties();
    private static PropertiesApp instance;

    private PropertiesApp() {

        try (InputStream file = getFile()) {

            properties.load(file);

        } catch (IOException e) {
            //TODO: Implementar Log
            throw new RuntimeException("Não foi possivel encontrar o arquivo de configuração", e);
        }
    }

    public static PropertiesApp getInstance() {
        if (instance != null) {
            return instance;
        }

        synchronized (PropertiesApp.class) {
            if (instance != null) {
                return instance;
            }

            instance = new PropertiesApp();
            return instance;

        }
    }

    private InputStream getFile() {
        return getClass().getResourceAsStream(PROPERTIES_FILE);
    }

    public String getPropertyValue(String property) {
        return properties.getProperty(property);
    }

}
